function login() {
    $("#index_login").click(function(){
        layer.open({
            type: 2,
            title: false,
            resize:false,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '400px'], //宽高
            content: '/login',
            success: function(layero, index){
                var iframe = $("iframe").eq(0);
                var username = iframe.contents().find("#login_username");
                var password = iframe.contents().find("#login_password");
                var btn = iframe.contents().find("#login_login");

                btn.click(function(){
                    var username = iframe.contents().find("#login_username").val();
                    var password = iframe.contents().find("#login_password").val();
                    if(username && password){
                        $.post("/login",{user:username,pwd:password},function (data) {
                            if(data === "true"){
                                location.reload(true);
                            }else {
                                layer.msg(data);
                            }
                        });
                    }else{
                        layer.msg('请输入用户名或密码');
                    }
                });
            }
        });
    });
}

$(function () {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    login();
});
